<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        *{
            margin: 0;
            padding: 0;
        }
        img{
            vertical-align: top;
            width: 100%;
        }
        section{
            width: 70%;
            margin: 0 auto;
        }
        .nav{
            position: fixed;
            left: 0;
            top: 0;
            width: 100%;
        }
    </style>
</head>
<body>
    <header id="header">
        <img src="./img/top.png" alt="">
    </header>
    <nav id="nav">
        <img src="./img/nav.png" alt="">
    </nav>
    <section>
        <img src="./img/body01.png" alt="">
        <img src="./img/body02.png" alt="">
    </section>

    <script src="./js/myTool.js"></script>
    <script>
        window.addEventListener('load',function(){
            //1、求出导航上边的高度
            let navTopH = $('nav').offsetTop;
            //2、监听页面滚动
            window.addEventListener('scroll',function(){
                let scrollH = scroll().top;
                // 3、判断
                if(scrollH>=navTopH){
                    $('nav').className = 'nav';
                }else{
                    $('nav').className = '';
                }
            })
        })
       
    </script>
</body>
</html>